package eiisan.service.task;

import com.fasterxml.jackson.core.JsonProcessingException;
import eiisan.dao.domain.user.Permission;
import eiisan.dao.repository.user.PermissionRepository;
import eiisan.service.task.base.TaskService;
import eiisan.service.user.dto.PermissionDTO;
import eiisan.service.user.mapper.PermissionMapper;
import eiisan.util.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Slf4j
@Component
@Transactional
@Service
public class PrintPermissionTask implements TaskService {
    @Autowired
    PermissionRepository permissionRepository;
    @Autowired
    PermissionMapper permissionMapper;

    @Override
    public String getDescription() {
        return "PrintPermissionTask测试";
    }

    @Override
    public void run() {
        List<Permission> all = permissionRepository.findAll();
        List<PermissionDTO> permissionDTOS = permissionMapper.toDto(all);
        String str = null;
        try {
            str = JSONUtil.string(permissionDTOS);
            System.out.println("PrintPermissionTask测试任务：");
            System.out.println(str);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
    }
}
